<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let promise = new Promise(resolve => resolve(1));

        promise.then(res => {
            console.log(res);
            return 2;
        }).then(res => {
            console.log(res);
            return 3;
        }).then(res => {
            console.log(res);
            // 这里返回一个错误的promise对象，那么下一个then函数中需要通过错误处理函数获取。
            return Promise.reject("错误4");
        }).then(null,err => {
            console.log("err = ",err);
        })

        // 使用catch可以作为 then(null,err => {})的别名
        promise = new Promise(resolve => resolve('a'));
        promise.then(res => {
            console.log(res);
            return Promise.reject('错误b');
        }).catch(err => {
            console.log("err = ",err);
        })
    </script>
</body>
</html>